<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签必须放在最前面，任何其他内容都必须跟随其后！ -->
    <title>search</title>
    <!-- Bootstrap样式 -->
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="jquery/jquery-3.4.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

    <!--前端渲染-->
    <script src="js/jsrender.js"></script>

    <link rel="stylesheet" href="css/Ymall.css">
    <link rel="stylesheet" href="css/Mall.css">
    <style>
        #copyRight-frame{
            position: fixed;
            bottom: 0;
            margin: auto;
        }
    </style>
</head>
<body>
<!-- navbar导航栏 -->
<nav class="navbar navbar-default">
    <div class="container-fluid" id="navbar">
        <div class="row clearfix">
            <div class="col-md-1 column">
            </div>
            <div class="col-md-10 column">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img class="img-logo" src="img/logol.png" alt=""></a>
                </div>

                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="Ymall.html"><span class="span-font">首页</span><span class="sr-only">(current)</span></a></li>
                        <li><a href="Mall.html"><span class="span-font">购物商城</span> </a></li>
                        <li><a href="#"><span class="span-font">求购商城</span> </a></li>
                        <li><a href="#"><span class="span-font">购物车</span> </a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="span-font">反馈与意见</span> <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#"><span class="span1-font">反馈</span></a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#"><span class="span1-font">意见</span></a></li>
                            </ul>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="span-font">联系我们</span> <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#"><span class="span1-font">电话联系</span></a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="#"><span class="span1-font">邮箱联系</span></a></li>
                            </ul>
                        </li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#"><span class="span-font">登录</span></a></li>
                        <li><a href="#"><span class="span-font">注册</span></a></li>
                    </ul>
                    <form class="navbar-form navbar-right">
                        <div class="form-group">
                            <input type="text" class="form-control" placeholder="Search">
                        </div>
                        <!-- <button type="submit" class="btn btn-default"><img class="img-search" src="img/" alt=""></button> -->
                        <button type="submit" class="btn btn-default"><img class="img-search" src="img/search_icon.png" alt=""></button>
                    </form>
                </div>
            </div>
            <div class="col-md-1 column">
            </div>
        </div>
    </div>
</nav>


<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-2 column">
        </div>
        <div class="col-md-10 column">
            <div class="col-md-4 column">
                <div class=" goods" id="goods0" style="margin-left: 10%;">
                </div>
                <div class=" goods" id="goods3" style="margin-left: 10%; margin-top: 20%;">
                </div>
                <div class=" goods" id="goods6" style="margin-left: 10%; margin-top: 20%;">
                </div>
            </div>
            <div class="col-md-4 column">
                <div class=" goods" id="goods1" style="margin-left: 10%;">
                </div>
                <div class=" goods" id="goods4" style="margin-left: 10%; margin-top: 20%;">
                </div>
                <div class=" goods" id="goods7" style="margin-left: 10%; margin-top: 20%;">
                </div>
            </div>
            <div class="col-md-4 column">
                <div class=" goods" id="goods2" style="margin-left: 10%;">
                </div>
                <div class=" goods" id="goods5" style="margin-left: 10%; margin-top: 20%;">
                </div>
                <div class=" goods" id="goods8" style="margin-left: 10%; margin-top: 20%;">
                </div>
            </div>
        </div>
    </div>
</div>

<!--copyright版权说明-->
<div class="container-fluid">
    <div class="row clearfix">
<!--        <div class="col-md-1 column">-->
<!--        </div>-->
<!--        <div class="col-md-12 column">-->
            <div id="copyRight-frame">
                <strong>Copyright © 2017-2200.Company name All rights reserved.</strong>
            </div>
<!--        </div>-->
<!--        <div class="col-md-1 column">-->
<!--        </div>-->
    </div>
</div>

<script id="theTmpl" type="text/x-jsrender">
<div class="thumbnail">
    <img alt="300x200" src="{{:images}}" style="width:300px; height:250px" />
    <div class="caption">
        <h3 style="margin-left:10%">{{:pname}}</h3>
        <p style="margin-left:33%">￥{{:price}}</p>
        <p style="margin-left:10%">{{:info}}</p>
        <p>
            <a class="btn btn-primary" onclick="add({{:pid}})">Buy</a>
        </p>
    </div>
 </div>
</script>

<script>

    var template = $.templates("#theTmpl");
    // $.get("http://localhost:8080/ycumall/ProductServlet?method=queryAll", function (data) {
    //     var len = data.data.length;
    //
    //     for (var i = 0; i < len; i++) {
    //         var htmlOutput = template.render(data.data[i]);
    //         $("#goods" + i).html(htmlOutput);
    //     }
    // });


    var likeName;
    function getLikeName() {
        var str = window.location.search;
        //search.html?name=likename
        var begin = str.indexOf("=")
        var likeName = str.slice(begin+1);
        likeName = decodeURI(likeName);
        return likeName;
    }
    $.get("http://localhost:8080/ycumall/ProductServlet?method=likeQuery&name="+getLikeName(), function (data) {
        if(data.data != null) {
            console.log(data.data);

            var len = data.data.length;

            for (var i = 0; i < len; i++) {
                var htmlOutput = template.render(data.data[i]);
                $("#goods" + i).html(htmlOutput);
            }

        } else {
            alert("没有该商品!");
            window.location.href="Mall.html";
        }
    });

</script>
</body>
</html>